package com.ant.map.myuiimmersive.views;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.TextView;

/**
 * Created by baichuan on 2016/12/12.
 */

public class View01 extends TextView {

    private int bg = Color.GRAY, col = Color.RED;
    private int width = 0, height = 0, cx, cy, radius = 0;

    private Paint paint;

    public View01(Context context) {
        super(context);
        initThisView(context, null, 0);
    }

    public View01(Context context, AttributeSet attrs) {
        super(context, attrs);
        initThisView(context, attrs, 0);
    }

    public View01(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initThisView(context, attrs, defStyleAttr);
    }

    private void initThisView(Context context, AttributeSet attrs, int defStyleAttr) {
        paint = new Paint();
        paint.setStrokeWidth(2);
        paint.setAntiAlias(true);
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);

        width = w;
        height = h;
        cx = width >> 1;
        cy = height >> 1;
        // 半径为长宽的最小值的一半
        radius = Math.min(w, h) >> 1;
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        // setMeasuredDimension(widthMeasureSpec,heightMeasureSpec);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        paint.setStyle(Paint.Style.FILL);
        paint.setColor(bg);
        canvas.drawCircle(cx, cy, radius, paint);
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(2);
        paint.setColor(Color.WHITE);
        canvas.drawCircle(cx, cy, radius >> 1, paint);
        super.onDraw(canvas);

    }
}
